<?php
namespace app\home\validate;

use think\Validate;

class UpGrade extends Validate
{
    protected $rule = [
        'rank_id'          => 'require|number|between:2,9|checRank:rank_id',
        'type'             => 'require',
    ];

    protected $message = [
        'rank_id.require'           => '请选择用户等级',
        'rank_id.number'            => '用户等级必须为数字',
        'rank_id.between'           => '用户等级错误',
        'rank_id.checRank'          => '用户等级错误',
        'type.require'              => '请选择支付类型',
    ];


    /**
     * 是否可以升级到该等级
     * @param int       $rank_id     要升级到该等级
     * @return bool
     */
    protected function checRank($rank_id)
    {
        if (session('user_info.rank_id') < $rank_id) {          // 等级判断
            return true;
        }else{
            return false;
        }
    }
}